package com.cn.aam.checaiduo.ui.me.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cn.aam.checaiduo.Const;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.adapter.BaseRecycerAdapter;
import com.cn.aam.checaiduo.base.adapter.holder.BaseRecyclerViewHolder;
import com.cn.aam.checaiduo.bean.me.InviteB;

import butterknife.BindView;

/**
 * monker on 2017/6/29.
 */

public class InviteAdapter extends BaseRecycerAdapter<InviteB.InviteListBean> {


    public InviteAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(View picNewsView) {
        return new InviteHolder(picNewsView);
    }

    @Override
    protected int getItemLayoutRes() {
        return R.layout.list_invite_item;
    }

    @Override
    protected void ItemVIewChange(BaseRecyclerViewHolder recyclerholder, int position) {
        InviteHolder holder = (InviteHolder) recyclerholder;


        String nickName = getItem(position).getNickname();
        if (TextUtils.isEmpty(nickName)) {
            String mobile = getItem(position).getMobile();
            if (!TextUtils.isEmpty(mobile)) {
                StringBuilder builder = new StringBuilder(mobile);
                builder.replace(3, 7, "****");
                holder.tvInviteName.setText(builder.toString());
            } else {
                holder.tvInviteName.setText("");
            }

        } else {
            if (nickName.length() > 2) {
                StringBuilder builder = new StringBuilder(nickName);
                builder.replace(0, nickName.length() - 1, "***");
                holder.tvInviteName.setText(builder.toString());
            } else {
                holder.tvInviteName.setText(nickName);
            }

        }


        if (TextUtils.equals("0", getItem(position).getInvested())) {
            holder.tvInvest.setText("否");
            holder.tvInvest.setTextColor(ContextCompat.getColor(mContext, R.color.textColor));
        } else {
            holder.tvInvest.setText("是");
            holder.tvInvest.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
        }

        if (TextUtils.equals(Const.AUTH_STATUS, getItem(position).getAuth_status())) {
            holder.tvInviteAutrh.setText("已认证");
            holder.tvInviteAutrh.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
        } else {
            holder.tvInviteAutrh.setText("未认证");
            holder.tvInviteAutrh.setTextColor(ContextCompat.getColor(mContext, R.color.textColor));
        }

    }


    class InviteHolder extends BaseRecyclerViewHolder {
        @BindView(R.id.tv_inviteName)
        TextView tvInviteName;
        @BindView(R.id.tv_inviteArth)
        TextView tvInviteAutrh;
        @BindView(R.id.tv_invest)
        TextView tvInvest;

        public InviteHolder(View itemView) {
            super(itemView);
        }
    }
}
